<template>
  <div class="app-container">
    <el-input
      placeholder="输入关键字进行过滤"
      v-model="filterText">
    </el-input>

    <el-tree
      class="filter-tree"
      :data="subjectTree"
      :props="defaultProps"
      :filter-node-method="filterNode"
      ref="tree">
    </el-tree>

  </div>
</template>

<script>
  export default {

    data() {
      return {
        filterText: '',
        subjectTree: [],
        defaultProps: {
          children: 'children',
          label: 'title'
        }
      }
    },
    watch: {
      filterText(val) {
        this.$refs.tree.filter(val);
      }
    },

    methods: {
      initSubjectTree(){
        this.getRequest("/eduservice/subject/").then(res=>{
          if(res){
            this.subjectTree=res.data.data
          }
        })
      },
      filterNode(value, data) {
        if (!value) return true
        return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
      }
    },
    mounted(){
      this.initSubjectTree()
    }
  }
</script>

